<template>
  <div>
    <h1 class="title">修改密码</h1>
    <div class="login">
      <div class="info">
        <div class="item">
          <i class="name"></i>
          <input v-model="name" disabled="true" placeholder="账号">
        </div>
        <div class="item">
          <i class="pwd"></i>
          <input v-model="password.password" type="password" placeholder="新密码">
        </div>
        <div class="item">
          <i class="pwds"></i>
          <input v-model="password.confirmPassword" type="password" placeholder="确认密码">
        </div>
        <div class="update">
          <button class="update_btn" @click="updatePwd()">确认修改</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {getCookie} from '../util/cookie'

  export default {
    name: "update-password",
    data() {
      return {
        name:getCookie('name'),
        password: {
          userId: getCookie('token'),
          password: '',
          confirmPassword: ''
        }
      }
    },
    methods: {
      updatePwd() {
        if (this.password.password.length <= 4) {
          this.$message({message: '请检查你的密码', type: 'warning'})
          return
        }
        if (this.password.password != this.password.confirmPassword) {
          this.$message({message: '您两次密码不一致', type: 'warning'})
          return
        }

        this.$post('/user/manager/admin/updatePwd',this.password,res=>{
          this.$message({message: '修改成功',type:'success'})
              this.password.password = ''
              this.password.confirmPassword = ''
        })
      }
    }
  }
</script>

<style scoped>
  .title {
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 20px 0;
  }

  .login {
    margin-top: 40px;
  }

  .login > .info {
    width: 300px;
    margin: 0 auto;
  }

  .login > .info > .item {
    margin-bottom: 20px;
    position: relative;
    border: 1px solid #0078ff;
    height: 40px;
    width: 100%;
  }

  .login > .info > .item > i {
    position: absolute;
    z-index: 3;
    top: 0;
    left: 0;
    width: 40px;
    height: 40px;
    border-right: 1px solid #0078ff;
    background-color: #0078ff;
  }

  .info > .item > i.name {
    background: url('../assets/user.png') no-repeat;
    background-size: 68%;
    background-position: 7px 6px;
  }

  .info > .item > i.pwd {
    background: url('../assets/pwd.png') no-repeat;
    background-size: 68%;
    background-position: 7px 6px;
  }

  .info > .item > i.pwds {
    background: url('../assets/ok.png') no-repeat;
    background-size: 68%;
    background-position: 7px 6px;
  }

  .info > .item > input {
    line-height: 18px;
    height: 18px;
    border: 0;
    padding-left: 51px;
    width: 248px;
    float: none;
    overflow: hidden;
    font-size: 14px;
    height: 38px;
    outline: none;
  }

  .info > .update {
    width: 100%;
    margin-top: 50px;
  }

  .info > .update > .update_btn {
    width: 100%;
    height: 40px;
    background-color: #0078ff;
    color: white;
    border: none;
    cursor: pointer;
    font-size: 18px;
  }
</style>
